<!-- <template>
	<view>
		<view class="uni-list">
			<view class="uni-list-cell" v-if="index !=0">
				<view class="uni-list-cell-left">
					定时
				</view>
				<view class="uni-list-cell-db">
					<picker mode="time" :value="time" @change="bindTimeChange">
						<view class="uni-input">{{time}}</view>
					</picker>
				</view>  
			</view>
			<view class="uni-list-cell uni-list-cell-pd" v-if="index ==0">
				<view class="uni-list-cell-db">是否强制执行</view>
				<switch :checked="option.minute==1" @change="minuteStateChange"  />
			</view>
			<view class="uni-list-cell uni-list-cell-pd">
				<view class="uni-list-cell-db">是否开启</view>
				<switch :checked="option.ledState==1" @change="ledStateChange"  />
			</view>
			<view class="uni-list-cell uni-list-cell-pd">
				<view class="uni-list-cell-db">
					温度
				</view>
				<view >
					<uni-number-box  :min="10" :max="200" v-model="option.temperature" background="#2979FF" color="#fff" />
				</view>
			</view>
			<view class="uni-list-cell">
				<button type="primary" @click="submit">提交</button>
			</view>
		</view>
	</view>
</template> -->
<template>
	<view class="container">
		<view class="fixed-header">
			<text class="header-title">设置</text>
		</view>
		<view class="content">
			<view class="settings-card">
				<view class="setting-item" v-if="index ==0">
					<view class="left-content" >
						<view class="icon-wrapper">
							<image class="custom-icon"
								src="https://ai-public.mastergo.com/ai/img_res/8a93f21cf6927f45d4487fa2203b4360.jpg"
								mode="aspectFill"></image>
						</view>
						<text class="setting-text">是否强制执行</text>
					</view>
					<switch :checked="option.minute==1" @change="minuteStateChange"color="#3B82F6" />
				</view>
				<view class="setting-item border-bottom"  v-else>
					<view class="left-content">
						<view class="icon-wrapper">
							<image class="custom-icon"
								src="https://ai-public.mastergo.com/ai/img_res/6243875676cdc98338b7ffa21b95db03.jpg"
								mode="aspectFill"></image>
						</view>
						<text class="setting-text">定时设置</text>
					</view>
					<picker mode="time" :value="time" @change="bindTimeChange">
						<text class="time-text">{{ time }}</text>
					</picker>
				</view>
				
				<view class="setting-item border-bottom">
					<view class="left-content">
						<view class="icon-wrapper">
							<image class="custom-icon"
								src="https://ai-public.mastergo.com/ai/img_res/9779766c8973da7a31087368becd836c.jpg"
								mode="aspectFill"></image>
						</view>
						<text class="setting-text">温度设置</text>
					</view>
					<view class="temp-controls">
						<!-- <input type="number" v-model="temperature" class="temp-value" @input="onTempInput" /> -->
						<uni-number-box  :min="10" :max="200" v-model="option.temperature" background="#2979FF" color="#fff" />

					</view>
				</view>
				<view class="setting-item">
					<view class="left-content">
						<view class="icon-wrapper">
							<image class="custom-icon"
								src="https://ai-public.mastergo.com/ai/img_res/8a93f21cf6927f45d4487fa2203b4360.jpg"
								mode="aspectFill"></image>
						</view>
						<text class="setting-text">开启状态</text>
					</view>
					<switch :checked="option.ledState==1" @change="ledStateChange"color="#3B82F6" />
				</view>
			</view>
		</view>
		<view class="fixed-footer">
			<uni-button type="primary" class="save-btn" @click="onSave">
				<uni-icons type="spinner-cycle" size="14" color="#FFFFFF"></uni-icons>
				<text>保存设置</text>
			</uni-button>
		</view>
	</view>
</template>


<script>
export default {
	data() {
		return {
			option: {},
			index: 0,
			time: '00:00'
		}
	},
	onLoad: function (option) {
		let item = JSON.parse(decodeURIComponent(option.option));
		this.index = option.index;
		this.option = item;
		console.log("this.option", this.option)
		this.time = item.hour.toString().padStart(2, '0') + ":" + item.minute.toString().padStart(2, '0');
	},
	methods: {
		bindTimeChange: function (e) {
			this.time = e.detail.value;
		},
		ledStateChange: function (e) {
			this.option.ledState = e.detail.value == true ? 1 : 0;
		},
		minuteStateChange: function (e) {
			this.option.minute = e.detail.value == true ? 1 : 0;
		},
		onSave: function () {
			const eventChannel = this.getOpenerEventChannel();
			console.log("this.option", this.option);

			let option = {
				ledState: this.option.ledState,
				temperature: this.option.temperature
			}
			if (this.index != 0) {
				option.hour = Number(this.time.split(":")[0]);
				option.minute = Number(this.time.split(":")[1]);
			} else {
				option.hour = this.option.hour;
				option.minute = this.option.minute;
			}

			eventChannel.emit('acceptDataFromOpenedPage', {
				option: option,
				index: Number(this.index)
			});
			uni.navigateBack();
		}
	}
}
</script>

<style>
page {
	height: 100%;
	background-color: #F9FAFB;
}

.container {
	height: 100%;
	display: flex;
	flex-direction: column;
}

.fixed-header {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	padding: 20rpx 32rpx;
	background-color: #FFFFFF;
	border-bottom: 1px solid #F3F4F6;
	z-index: 10;
}

.header-title {
	font-size: 16px;
	font-weight: 500;
	color: #1F2937;
}

.content {
	flex: 1;
	padding: 108rpx 32rpx 168rpx;
}

.settings-card {
	background-color: #FFFFFF;
	border-radius: 16rpx;
	box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
}

.setting-item {
	padding: 32rpx;
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.border-bottom {
	border-bottom: 1px solid #F3F4F6;
}

.left-content {
	display: flex;
	align-items: center;
	gap: 24rpx;
}

.icon-wrapper {
	width: 64rpx;
	height: 64rpx;
	border-radius: 64rpx;
	background-color: rgba(59, 130, 246, 0.1);
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
}

.custom-icon {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.setting-text {
	font-size: 14px;
	color: #1F2937;
}

.time-text {
	font-size: 14px;
	color: #1F2937;
}

.temp-header {
	width: 100%;
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.temp-controls {
	display: flex;
	align-items: center;
	justify-content: flex-end;
	min-width: 80rpx;
}

.temp-value {
	font-size: 18px;
	font-weight: 500;
	color: #1F2937;
	text-align: right;
	background-color: transparent;
	border: none;
}

.fixed-footer {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	padding: 32rpx;
	background-color: #FFFFFF;
	border-top: 1px solid #F3F4F6;
}

.save-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 16rpx;
	border-radius: 8rpx !important;
}
</style>
